<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>检查组管理</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>检查组管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table
                            :data="tableData"
                            style="width: 100%">
                        <el-table-column
                                prop="code"
                                label="code"
                                width="180">
                        </el-table-column>
                        <el-table-column
                                prop="name"
                                label="name"
                                width="180">
                        </el-table-column>

                        <el-table-column
                                label="操作"
                                width="180">

                            <span slot-scope="scope">

                                 <el-button v-on:click="handleEdit(scope)" type="primary" icon="el-icon-edit" circle></el-button>
                                 <el-button v-on:click="handleDelete(scope)" type="danger" icon="el-icon-delete" circle></el-button>
                            </span>


                        </el-table-column>

                    </el-table>

                    <el-pagination
                            @current-change="handleCurrentChange"
                            :current-page.sync="currentPage"
                            :page-size="pageSize"
                            layout="total, prev, pager, next"
                            :total="totalSize">
                    </el-pagination>


                    <el-dialog title="新增检查组" :visible.sync="dialogFormVisibleAdd">

                        <el-tabs v-model="activeName">
                            <el-tab-pane label="基本信息" name="first">
                                <table>
                                    <tr>
                                        <td>code</td>
                                        <td>
                                            <el-input v-model="formData.code"></el-input>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>name</td>
                                        <td> <el-input v-model="formData.name"></el-input></td>
                                    </tr>
                                    <tr>
                                        <td>sex</td>
                                        <td>
                                            <el-select v-model="formData.sex" >
                                                <el-option label="男" value="1"></el-option>
                                                <el-option label="女" value="2"></el-option>
                                            </el-select>
                                        </td>
                                    </tr>
                                </table>
                            </el-tab-pane>
                            <el-tab-pane label="检查项信息" name="second">
                                <table>
                                    <tr v-for="item in checkItems">
                                        <td>
                                            <input v-model="checkitemIds" type="checkbox" :value="item.id">
                                        </td>
                                        <td>
                                            {{item.code}}
                                        </td>
                                        <td>
                                            {{item.name}}
                                        </td>
                                    </tr>
                                </table>
                            </el-tab-pane>
                        </el-tabs>


                        <el-button v-on:click="dialogFormVisibleAdd = false">取消</el-button>
                        <el-button type="primary" v-on:click="handleAdd()">提交</el-button>

                    </el-dialog>



<!--                     修改窗口-->
                    <el-dialog title="编辑检查组" :visible.sync="dialogTableVisibleEdit">
                        <el-tabs v-model="activeName">
                            <el-tab-pane label="用户管理" name="first">

                                <table>
                                    <tr>
                                        <td>code</td>
                                        <td>
                                            <el-input v-model="formData.code"></el-input>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>name</td>
                                        <td> <el-input v-model="formData.name"></el-input></td>
                                    </tr>
                                    <tr>
                                        <td>sex</td>
                                        <td>
                                            <el-select v-model="formData.sex" >
                                                <el-option label="男" value="1"></el-option>
                                                <el-option label="女" value="2"></el-option>
                                            </el-select>
                                        </td>
                                    </tr>
                                </table>

                            </el-tab-pane>
                            <el-tab-pane label="配置管理" name="second">


                                <table>
                                    <tr v-for="item in checkItems">
                                        <td>
                                            <input v-model="checkitemIds" type="checkbox" :value="item.id">
                                        </td>
                                        <td>
                                            {{item.code}}
                                        </td>
                                        <td>
                                            {{item.name}}
                                        </td>
                                    </tr>
                                </table>

                            </el-tab-pane>
                        </el-tabs>


                        <el-button v-on:click="dialogTableVisibleEdit = false">取消</el-button>
                        <el-button type="primary" v-on:click="handleDoEdit()">提交</el-button>
                    </el-dialog>

                </div>
            </div>
        </div>
    </body>

    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                tableData:[],//分页查询检查组的信息
                currentPage:1,
                pageSize:10,
                totalSize:100,//总页数
                dialogFormVisibleAdd:false,//新增窗口
                dialogTableVisibleEdit:false,//编辑窗口
                activeName:'first',
                formData:{},//检查组的基本信息
                checkItems:[],//所有的检查项信息
                checkitemIds:[],//用户勾选的检查项id集合
            },
            created() {
                this.findPage();
            },
            methods: {
                //分页组件页码变化时触发的事件
                handleCurrentChange(page){
                    this.currentPage = page;
                    this.findPage();
                },
                handleCreate(){
                    //弹出新增框
                    this.dialogFormVisibleAdd = true
                    //查询所有的检查项信息供用户勾选
                    axios.get("/checkitem/findAll.do").then((res)=>{
                        //res.data={flag:boolean,message:string,data:object}
                        this.checkItems = res.data.data;
                    })
                },
                handleAdd(){
                    this.formData.checkitemIds = this.checkitemIds;
                    axios.post("/checkgroup/add.do",this.formData).then(()=>{
                        this.dialogFormVisibleAdd = false;
                    })
                },
                findPage(){
                    //把当前页&每页显示数量传给后端
                    let param = {
                        currentPage: this.currentPage,
                        pageSize: this.pageSize,
                    }

                    axios.post("/checkgroup/findPage.do",param).then((res)=>{
                        // res.data = {rows:list,total:int}
                        this.tableData = res.data.rows;
                        this.totalSize = res.data.total;
                    })
                },
                handleEdit(scope){
                    console.log(scope.row.id);
                    //根据检查组id查询检查组的详情

                    //查询所有的检查项

                    //查询当前检查组下面的检查项id集合
                    axios.get("/checkgroup/findByIdBatch.do?id=" + scope.row.id).then((res)=>{
                        this.dialogTableVisibleEdit = true;
                        this.formData = res.data.data.checkGroup;
                        this.checkItems = res.data.data.checkItems;
                        this.checkitemIds = res.data.data.checkItemIds;
                    })


                },
                handleDelete(scope){

                },
                handleDoEdit(){
                    this.formData.checkitemIds = this.checkitemIds;
                    axios.post("/checkgroup/edit.do",this.formData).then(()=>{
                        this.dialogTableVisibleEdit = false;
                    })

                }
            }
        })
    </script>
</html>
